//
//  LoginVC.swift
//  easyVideo-swift
//
//  Created by 李淼淼 on 2021/7/30.
//

import UIKit

class LoginVC: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var serverTF: UITextField!
    @IBOutlet weak var accoutTF: UITextField!
    @IBOutlet weak var passwordTF: UITextField!
    @IBOutlet weak var loginButton: UIButton!
    @IBOutlet weak var adviceButton: UIButton!
    

    override func viewDidLoad() {
        super.viewDidLoad()

        //设置圆角
        loginButton.layer.cornerRadius = 4.0
        //设置文字
        adviceButton.setTitle("高级设置", for: .normal)
        //绑定按钮方法
        loginButton.addTarget(self, action: #selector(loginAction), for: .touchUpInside)
        
        //设置默认输入内容
        serverTF.text = "192.168.0.1"
        accoutTF.text = "limiaomiao"
        passwordTF.text = "123456"
        //设置代理
        serverTF.delegate = self
        accoutTF.delegate = self
        passwordTF.delegate = self
        
       
    }

    @IBAction func backAction(_ sender: Any) {
        //返回上一个界面
        self.navigationController?.popViewController(animated: true)
    }
    
    //添加按钮方法
    @objc func loginAction() ->Void{
        print("点击了登录")
        if serverTF.text?.count == 0 {
            print("用户没有输入服务器")
        }else if accoutTF.text?.count == 0 {
            print("用户没有输入用户名")
        }else if passwordTF.text?.count == 0 {
            print("用户没有输入密码")
        }else if passwordTF.text?.count ?? 0 < 6 {
            print("密码小于6位了")
        }
        
    }
    //实现代理的方法
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        //循环判断
        switch textField {
        case serverTF:
            //server 不允许超过6个数
            if serverTF.text!.count > 5 {
                //提示框
                let alert = UIAlertController.init(title: "提示", message: "不允许超过6位数", preferredStyle: .alert)
                present(alert, animated: true, completion: nil)
            }
            break
        case accoutTF:
            if accoutTF.text!.count > 9 {
                let alert = UIAlertController.init(title: "提示", message: "不允许超过10个数", preferredStyle: .alert)
                present(alert, animated: true, completion: nil)
            }
            break
        case passwordTF:
            if passwordTF.text!.count > 10 {
                let alert = UIAlertController.init(title: "提示", message: "不允许超过11个数", preferredStyle: .alert)
                present(alert, animated: true, completion: nil)
            }
            break
        default:
            break
        }
        return true
       
        
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
